﻿// Copyright (c) Vitaly Kamiansky. All rights reserved. 
// See License.txt in the project root.

using System;

namespace Property.Reloaders
{
    public partial class StateFilterReloaderDecoratorPrototype<T, TState> : ReloaderDecoratorPrototype<T>
    {
        public StateFilterReloaderDecoratorPrototype(IReloaderPrototype<T> compositionBasePrototype, Func<TState, TState> getFilterState, Func<IObservable<TState>, IObservable<TState>> filter)
            : base(compositionBasePrototype)
        {
            _GetFilterState = getFilterState;
            _Filter = filter;
        }

        //=//

        private readonly Func<TState, TState> _GetFilterState;
        private readonly Func<IObservable<TState>, IObservable<TState>> _Filter;

        public override IReloader Create(Func<T> getValue, Action<T> applyValue, Action<bool> applyStatus)
        {
            return new DecoratorInstance(_CompositionBasePrototype, getValue, applyValue, applyStatus, _GetFilterState,  _Filter);
        }
    }
}
